package com.ego.controller;

import com.ego.pojo.EasyUITree;
import com.ego.pojo.EgoResult;
import com.ego.service.ContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ContentCategoryController {

    @Autowired
    private ContentCategoryService contentCategoryService;

    @RequestMapping("/content/category/list")
    @ResponseBody
    public List<EasyUITree> selectContentCategoryList(@RequestParam(value = "id", defaultValue = "0") Long pid) {
        return contentCategoryService.selectContentCategoryByParenId(pid);
    }

    @RequestMapping("/content/category/create")
    @ResponseBody
    public EgoResult creatContentCategory(Long parentId, String name) {
        return contentCategoryService.saveContentCategory(parentId, name);
    }

    @RequestMapping("/content/category/update")
    public EgoResult update(Long id, String name) {
        return contentCategoryService.updateContentCategory(id, name);
    }

    @RequestMapping("/content/category/delete")
    @ResponseBody
    public EgoResult delete(Long id){
        return contentCategoryService.deleteContentCategoryById(id);
    }

}
